/**
 * Created by sa on 16-9-9.
 */
$(function () {
    if(!sessionStorage.getItem("count")){
        $("#header").css("visibility","visible");
        $(".header_next").show();
    }
    $("#header .close").on("click",function () {
        sessionStorage.setItem("count",1);
        $(this).parents("#header").next().hide();
        $(this).parents("#header").hide();
    });

    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    video_info();
    //视频详情接口
    function video_info(a,b) {
        var video_id = a?a:GetQueryString("video_id");
        $.ajax({
            type:"GET",
            url:"http://api.headlines.video/api/video/info?video_id="+video_id+"&device_id=1",
            success:function (res) {
                var data= JSON.parse(res);
                var html = template("video_detail",data.data);
                $("#video").html(html);
                $(".video_play_name_right").on("click",function () {
                    window.location.href="https://itunes.apple.com/us/app/chao-ji-tou-tiao/id1149308012?l=zh&ls=1&mt=8";
                });
                var videoJs =  videojs("my-video",{
                    techOrder : ["html5"]
                });
                $(".vjs-big-play-button").on("click",function (e) {
                    videoJs.play();
                    e.preventDefault();
                });
                /*
                $(".video_palay_pause").on("click",function () {
                    $(this).hide();
                    $("video")[0].play();
                });
                $("video")[0].addEventListener("pause",function () {
                    $(".video_palay_pause").show();
                })*/
                video_list(a,b);
            }
        });
    }
    //视频列表接口
    function video_list(a,b) {
        var video_id = a?a:GetQueryString("video_id");
        $.ajax({
            type:"GET",
            url:"http://api.headlines.video/api/recommend/vidoe/reated?video_id="+video_id+"&device_id=1",
            success:function (res) {
                var data= JSON.parse(res);
                var html = template("video_list",data);
                $(".video_list").append(html);
                $(".video_list ul li").on("click",function () {
                    var _id=$(this).attr("_id");
                    window.location.href="index.html?video_id="+_id+"&device_id=1";
                    //video_info(_id);
                });
                $(".video_play_name_left").on("click",function () {
                    window.location.href="../html/detail.html?media_id="+$(this).attr("media_id")+"&device_id=1";
                })
            }
        })
    }

});